package com.bree.erp.service.util;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import javax.xml.bind.DatatypeConverter;

public final class ServiceUtil {

	public static String encodePassword(String password) {
		
		MessageDigest md = null;
		
		if (md == null) {
			try {
				md = MessageDigest.getInstance("SHA-256");
			} catch (NoSuchAlgorithmException ex) {
				ex.printStackTrace();
			}
		}
		try {
			md.update(password.getBytes("UTF-8"));
			byte[] digest = md.digest();
			return DatatypeConverter.printBase64Binary(digest).toString();
		} catch (UnsupportedEncodingException ex) {
			ex.printStackTrace();
		}
		return null;
	}

}
